/**
 *  button_box.vala
 *
 *  Copyright (c) 2007 Marcelo Lira dos Santos <setanta@gmail.com>
 *                2007 INdT (Instituto Nokia de Technologia)
 *
 *  Author: Marcelo Lira dos Santos <setanta@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA
 */

using GLib;
using Gtk;

public class ButtonBoxDemo : GLib.Object
{

    Frame create_bbox (bool  horizontal,
                       string title,
                       int  spacing,
                       ButtonBoxStyle layout)
    {
        Frame frame;
        ButtonBox bbox;
        Button button;

        frame = new Frame(title);

        if (horizontal)
            bbox = new HButtonBox();
        else
            bbox = new VButtonBox();

        frame.add(bbox);

        bbox.border_width = 5;
        bbox.layout_style = layout;
        bbox.spacing = spacing;

        button = new Button.from_stock(STOCK_OK);
        bbox.add(button);

        button = new Button.from_stock(STOCK_CANCEL);
        bbox.add(button);

        button = new Button.from_stock(STOCK_HELP);
        bbox.add(button);

        return frame;
    }

    public Window do_button_box ()
    {
        Window window = null;
        VBox main_vbox;
        VBox vbox;
        HBox hbox;
        Frame frame_horz;
        Frame frame_vert;

        window = new Window(WindowType.TOPLEVEL);
        window.title = "Button Boxes";
        window.border_width = 10;
        window.destroy += Gtk.main_quit;

        main_vbox = new VBox(false, 0);
        window.add(main_vbox);

        frame_horz = new Frame("Horizontal Button Boxes");
        main_vbox.pack_start(frame_horz, true, true, 10);

        vbox = new VBox(false, 0);
        vbox.border_width = 10;
        frame_horz.add(vbox);

        vbox.pack_start(create_bbox(true, "Spread", 40,
                                    ButtonBoxStyle.SPREAD),
                        true, true, 0);

        vbox.pack_start(create_bbox(true, "Edge", 40,
                                    ButtonBoxStyle.EDGE),
                        true, true, 5);

        vbox.pack_start(create_bbox(true, "Start", 40,
                                    ButtonBoxStyle.START),
                        true, true, 5);

        vbox.pack_start(create_bbox(true, "End", 40,
                                    ButtonBoxStyle.END),
                        true, true, 5);

        frame_vert = new Frame("Vertical Button Boxes");
        main_vbox.pack_start(frame_vert, true, true, 10);

        hbox = new HBox(false, 0);
        hbox.border_width = 10;
        frame_vert.add(hbox);

        hbox.pack_start(create_bbox(false, "Spread", 30,
                                    ButtonBoxStyle.SPREAD),
                        true, true, 0);

        hbox.pack_start(create_bbox(false, "Edge", 30,
                                    ButtonBoxStyle.EDGE),
                        true, true, 5);

        hbox.pack_start(create_bbox(false, "Start", 30,
                                    ButtonBoxStyle.START),
                        true, true, 5);

        hbox.pack_start(create_bbox(false, "End", 30,
                                    ButtonBoxStyle.END),
                        true, true, 5);

        return window;
    }

    static int main (string[] args) {
        Gtk.init(out args);

        ButtonBoxDemo bb = new ButtonBoxDemo();

        var win = bb.do_button_box();
        try {
            win.set_default_icon_from_file("v-icon.png");
        } catch (GLib.Error error) {
            critical(error.message);
        }
        win.show_all();

        Gtk.main();

        return 0;
    }
}
